package com.pi.shisan.service.service.impl.next;

import com.pi.shisan.service.annotation.CalcNextTimeType;
import com.pi.shisan.service.constants.ClockTypeEnum;
import com.pi.shisan.service.dto.ClockInfoDTO;
import com.pi.shisan.service.exception.BusinessException;
import com.pi.shisan.service.service.ClockNextTimeService;

import java.time.LocalDateTime;
import java.time.ZoneId;

@CalcNextTimeType(ClockTypeEnum.NO_REPEAT)
public class NoRepeatNextTimeServiceImpl implements ClockNextTimeService {
    @Override
    public Long calc(ClockInfoDTO clockInfoDTO) {
        Integer year = clockInfoDTO.getClkYear();
        Integer month = clockInfoDTO.getClkMonth();
        Integer day = clockInfoDTO.getClkDay();
        Integer hour = clockInfoDTO.getClkHour();
        Integer minute = clockInfoDTO.getClkMinute();
        long timestamp = LocalDateTime.of(year,month,day,hour,minute,0).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
        if (timestamp <= System.currentTimeMillis()) {
            throw new BusinessException("此闹铃已失效");
        }
        return timestamp;
    }
}
